Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a proper sqlite3 database to RootPythia #44

Merged
merged 20 commits into from
Aug 31, 2024
Merged

Add a proper sqlite3 database to RootPythia #44

merged 20 commits into from
Aug 31, 2024

Conversation

ctmbl
Copy link
Contributor

@ctmbl ctmbl commented Dec 24, 2023

I replaced the DummyDBManager by a "real" DatabaseManager which initializes (in _init_db) and uses a database file $DB_FOLDER/RootPythia.db, configurable by environment variable. I also moved it to a separated src/database sub directory.

All SQL queries templates are stored in database/db_structure.py (which could as well be named db_queries), and the bot is safe from SQLi because I only used the sqlite3 safe substitution using ? in queries.
The API hasn't change, apart from the class name, so the tests with slight changes still pass which gives me strong confidence in the bot working well.

The Database is currently only composed of one users table which stores exactly the same information that the previous python list stored. Improving this, is outside of the scope of this PR and will be done later as well as other bug fixes (rank and score that don't change when fetching new challenges). The DatabaseManager still returns Users objects to comply with other classes APIs, the conversion from the DB data to the User object (and vice versa) has been done thanks to slight additions to the User class to be developer-friendly.

I mainly used this tutorial: https://www.sqlitetutorial.net/sqlite-python/

@ctmbl ctmbl added the enhancement New feature or request label Dec 24, 2023
@ctmbl ctmbl requested review from atxr and Xlitoni December 24, 2023 08:43
@ctmbl ctmbl self-assigned this Dec 24, 2023
@ctmbl ctmbl linked an issue Dec 27, 2023 that may be closed by this pull request
@ctmbl
Copy link
Contributor Author

ctmbl commented Mar 5, 2024

@ZynoXelek could you take a look?

Copy link
Contributor

@ZynoXelek ZynoXelek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I didn't comment was clear and looks good to me.
Once my questions will be answered, I will approve this PR.

src/bot/root_pythia_bot.py Show resolved Hide resolved
src/database/__init__.py Outdated Show resolved Hide resolved
src/database/db_manager.py Show resolved Hide resolved
tests/conftest.py Show resolved Hide resolved
@ctmbl ctmbl merged commit 685f41e into iScsc:main Aug 31, 2024
2 checks passed
@ctmbl ctmbl deleted the db branch August 31, 2024 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move to a real persistent database
2 participants